// ===========================================================
// Integers:  Miscellaneous integer arithmetic exercises.
// ============================================================

`timescale 1ns/100ps

module Integers;
  
  integer   iX, iA, iB;
  reg[31:0] rX, rA, rB;
 
  reg [8:0] test;

  initial
    begin
    
    #1 iX =   0; iA =   0; iB =   0; // time = 1
       rX = 'b0; rA = 'b0; rB = 'b0;
    // A. Signed (simple) integers:
       iA = 16;
       iB = -8;
    #1 iX = iA + iB; $display("iA=%0d, iB=%0D,ix=iA+iB=%0d",iA,iB,iX); 
    #1 iX = iA - iB; $display("iA=%0d, iB=%0D,ix=iA-iB=%0d",iA,iB,iX);
    #1 iX = iB - iA; $display("iB=%0d, iA=%0D,ix=iB-iA=%0d",iB,iA,iX);
    #1 iX =   0; iA =   0; iB =   0; // time = 5
       rX = 'b0; rA = 'b0; rB = 'b0;
    // B. Registers (unsigned):
       rA = 32'd16;
       rB = -32'd8;
       test = -9'h1;$display("test=9'b%b", test); 
       test = -9'h2;$display("test=9'b%b", test); 
    #1 rX = rA + rB;$display("rA=%0d, rB=%0d,rx=rA+rB=%0d",rA,rB,rX); 
    #1 rX = rA - rB;$display("rA=%0d, rB=%0d,rx=rA-rB=%0d",rA,rB,rX); 
    #1 rX = rB - rA;$display("rA=%0d, rB=%0d,rx=rB-rA=%0d",rA,rB,rX); 
    #1 iX =   0; iA =   0; iB =   0; // time = 9
       rX = 'b0; rA = 'b0; rB = 'b0;
    // C. Just X integer:
       rA = 32'd16;
       rB = -32'd8;
    #1 iX = rA + rB;$display("rA=%0d, rB=%0d,iX=rA+rB=%0d",rA,rB,iX); 
    #1 iX = rA - rB;$display("rA=%0d, rB=%0d,iX=rA-rB=%0d",rA,rB,iX); 
    #1 iX = rB - rA;$display("rA=%0d, rB=%0d,iX=rB-rA=%0d",rA,rB,iX); 
    #1 iX =   0; iA =   0; iB =   0; // time = 13
       rX = 'b0; rA = 'b0; rB = 'b0;
    // C. Just A integer:
       iA = 16;
       rB = -32'd8;
    #1 rX = iA + rB;$display("iA=%0d, rB=%0d,rx=iA+rB=%0d",iA,rB,rX); 
    #1 rX = iA - rB;$display("iA=%0d, rB=%0d,rx=iA-rB=%0d",iA,rB,rX); 
    #1 rX = rB - iA;$display("iA=%0d, rB=%0d,rx=rB-rA=%0d",iA,rB,rX); 
    #1 iX =   0; iA =   0; iB =   0; // time = 17
       rX = 'b0; rA = 'b0; rB = 'b0;
    // C. Just B integer:
       rA = 32'd16;
       iB = -8;
    #1 rX = rA + iB;$display("rA=%0d, iB=%0d,rx=rA+iB=%0d",rA,iB,rX);
    #1 rX = rA - iB;$display("rA=%0d, iB=%0d,rx=rA-iB=%0d",rA,iB,rX);
    #1 rX = iB - rA;$display("rA=%0d, iB=%0d,rx=iB-rA=%0d",rA,iB,rX);
    #1 iX =   0; iA =   0; iB =   0; // time = 21
       rX = 'b0; rA = 'b0; rB = 'b0;
    #2 $finish;
    end
  
endmodule // Integers.
